package com.learn.spring;

import com.learn.spring.bean.Person;
import com.learn.spring.java_config.*;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        App app = new App();
//        app.testConfigurationNotLazyLoad();
//        app.testConfigurationLazyLoad();
//        app.testConfigurationPrototypeLoad();
//        app.testImportConfig();
//        app.testBeanLifeCycleConfig();
        app.testConfiguration();
//        app.testValueConfig();

    }

    public void testConfiguration() {
        Class configClass = MainConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        System.out.println(context.getBean("person"));
    }

    public void testComponentScanConfig() {
        Class configClass = MainComponentScanConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        System.out.println(context.getBean("dog"));
        System.out.println(context.getBean("person"));
    }

    public void testComponentScanExcludeConfig() {
        Class configClass = MainComponentScanExcludeConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        System.out.println(context.getBean("dog"));
        System.out.println(context.getBean("person"));
    }

    public void testComponentScanIncludeConfig() {
        Class configClass = MainComponentScanIncludeConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        System.out.println(context.getBean("dog"));
        System.out.println(context.getBean("person"));
    }

    public void testConfigurationSimple() {
        Class configClass = MainConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        Person person1 = context.getBean("person", Person.class);
        Person person2 = context.getBean("person", Person.class);
        System.out.println(person1 == person2);
    }

    public void testConfigurationNotLazyLoad() {
        Class configClass = MainConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
    }

    public void testConfigurationLazyLoad() {
        Class configClass = MainLazyConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
    }

    public void testConfigurationPrototypeLoad() {
        Class configClass = MainScopeConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        Person person1 = context.getBean("person", Person.class);
        Person person2 = context.getBean("person", Person.class);
        System.out.println(person1 == person2);
    }

    public void testConditionalConfig() {
        Class configClass = MainConditionalConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        context.getBean("person");
    }

    public void testImportConfig() {
        Class configClass = MainImportConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        context.getBean("person");
        context.getBean("personImport");
        context.getBean("dogImport");
    }

    public void testBeanLifeCycleConfig() {
        Class configClass = MainLifeCycleConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        context.getBean("person");
        context.getBean("dog");
        System.out.println(context.getBean("person") == context.getBean("person"));
    }

    public void testValueConfig() {
        Class configClass = MainValueConfig.class;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
        context.getBean("person");
//        context.getBean("dog");
        System.out.println(context.getBean("person"));
    }
}
